﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MainForm
{
    public partial class Form1 : Form
    {


        private int mCurrentQuestionIndex = (int) QuestionState.MAIN_COMPLAIN_LOCATION;
        private Dictionary<QuestionState, UserControl> mControlsMap = new Dictionary<QuestionState, UserControl>();
        
        public Form1()
        {
            InitializeComponent();

            // The default one (the first one)
            mControlsMap.Add(QuestionState.MAIN_COMPLAIN_LOCATION, questionControl);

            Array values = Enum.GetValues(typeof(QuestionState));
            for (int i = 1; i < values.Length; i++)
            {
                QuestionState qs = (QuestionState)values.GetValue(i);

                mControlsMap.Add(qs, createUserControl(qs));
            }
        }

        private void btnNext_Click(object sender, EventArgs e)
        {
            QuestionState prevQuestion   = (QuestionState) mCurrentQuestionIndex++;
            QuestionState nextQuestion   = (QuestionState) mCurrentQuestionIndex;

            // Hide the original
            mControlsMap[prevQuestion].Visible = false;

            // Show the new one
            mControlsMap[nextQuestion].Visible = true;

            if (mCurrentQuestionIndex == mControlsMap.Count)
            {
                btnNext.Enabled = false;
            }

            btnPrev.Enabled = true;
        }

        private void btnPrev_Click(object sender, EventArgs e)
        {
            QuestionState nextQuestion = (QuestionState)mCurrentQuestionIndex--;
            QuestionState prevQuestion = (QuestionState)mCurrentQuestionIndex;
            
            // Hide the original
            mControlsMap[nextQuestion].Visible = false;

            // Show the new one
            mControlsMap[prevQuestion].Visible = true;

            if (mCurrentQuestionIndex == 1)
            {
                btnPrev.Enabled = false;
            }

            btnNext.Enabled = true;
        }

        private UserControl createUserControl(QuestionState pQuestionState)
        {
            UserControl userControl = null;

            switch (pQuestionState)
            { 
                case QuestionState.MAIN_COMPLAIN_LOCATION:
                    userControl = new StartProblemTimeQ();
                    break;
                case QuestionState.MAIN_COMPLAIN_DESCRIPTION:
                    userControl = new MainComplainDescriptionQ();
                    break;
                case QuestionState.PROBLEM_START_TIME:
                    userControl = new ProblemStartTimeQ();
                    break;
                default:
                    break;
            }

            manageUserControl(userControl);

            return userControl;
        }

        private void manageUserControl(UserControl pUserControl)
        {
            pUserControl.Location = new System.Drawing.Point(50, 14);
            pUserControl.Name = "mainComplainLocationQ1";
            pUserControl.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
            pUserControl.Size = new System.Drawing.Size(780, 371);
            pUserControl.TabIndex = 0;
            pUserControl.Visible = false;

            panel1.Controls.Add(pUserControl);
        }
    }
}
